
Page({
  data: {
    imgSrc: '',
    location: {}
  },
  chooseLocation() {
    /*wx.getLocation({
      type: 'wgs84',
      success (res) {
        console.log(res)
        const latitude = res.latitude
        const longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
      }
    })*/
    const self = this
    wx.chooseLocation({
      success(res) {
        console.log(res)
        // latitude: 34.340377
        // longitude: 108.939478
        self.setData({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          }
        })
      }
    })
  },
  openLocation() {
    wx.openLocation({
      latitude: this.data.location.latitude,
      longitude: this.data.location.longitude
    })
  },
  toTop() {
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300
    })
  },
  showAction() {
    const self = this
    wx.showActionSheet({
      alertText: '选择你的操作',
      itemList: ['相册', '拍照', '录视频'],
      itemColor: 'red',
      success (res) {
        switch (res.tapIndex) {
          case 0:
            wx.chooseImage({
              count: 1,
              sizeType: ['original', 'compressed'],
              sourceType: ['album'],
              success (res) {
                // tempFilePath可以作为img标签的src属性显示图片
                const tempFilePaths = res.tempFilePaths
                // console.log(tempFilePaths)
                self.setData({
                  imgSrc: tempFilePaths[0]
                })
              }
            })
            break
          case 1:
            wx.chooseImage({
              count: 1,
              sizeType: ['original', 'compressed'],
              sourceType: ['camera'],
              success (res) {
                // tempFilePath可以作为img标签的src属性显示图片
                const tempFilePaths = res.tempFilePaths
                console.log(res)
              }
            })
            break
        }
        /*console.log(res)
        if(res.tapIndex === 1) {
          wx.showNavigationBarLoading()
        } else if (res.tapIndex === 0) {
          wx.setNavigationBarTitle({
            title: '当前页面'
          })
          wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: '#ff0000',
            animation: {
              duration: 400,
              timingFunc: 'easeIn'
            }
          })
        }*/
      },
      fail (res) {
        console.log(res.errMsg)
      }
    })
  },
  linkTo(event) {
    const {url} = event.currentTarget.dataset
    // wx.reLaunch({url})
    // wx.redirectTo({url: '../form/form'})
    // wx.navigateTo({url: '../form/form'})
    wx.showModal({
      title: '提示',
      content: '这是一个模态弹窗',
      // showCancel: false,
      cancelText: 'cancel',
      cancelColor: 'red',
      success (res) {
        console.log(res)
        if (res.confirm) {
          console.log('用户点击确定')
          wx.navigateTo({url: '../form/form'})
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })


    /*wx.switchTab({
      url
    })*/
  },
  onLoad() {
    /*
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 3000)
    */

    /*
    wx.showToast({
      title: '成功',
      icon: 'none',
      duration: 20000,
      mask: true
    })
    */
    wx.getSystemInfo({
      success(res) {
        console.log(res)
      }
    })
  }

})
